#!/usr/bin/perl -w

use strict;

my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime();    
$year += 1900;    
$mon++;
my $date = "$year-$mon-$day";

sub gen_c
{
	my ($unit) = @_;
	my $c_file = "$unit.cpp";
    my $c_template = <<"__TEMPLATE";
/**
 * copyright 2014 by luobiliu
 *
 * \@file:       $c_file
 * \@author:     luobiliu
 * \@version:    1.0
 * \@date:       $date
 *
 */

#include "$unit\.h"

USING_NS_CC;


__TEMPLATE

	open (FH, ">$c_file") or die $!;
	print FH $c_template;
	close FH;
}

sub gen_h
{
	my ($unit) = @_;
	my $h_file = "$unit.h";
	my $h_marco = $h_file;
	$h_marco =~ s/\./_/g;
	$h_marco = "__" . uc($h_marco) . "__";
    my $h_template = <<"__TEMPLATE";
/**
 * copyright 2014 by luobiliu
 *
 * \@file:       $h_file
 * \@author:     luobiliu
 * \@version:    1.0
 * \@date:       $date
 *
 */

#ifndef $h_marco
#define $h_marco
#include "cocos2d.h"

class $unit: public cocos2d::CCObject
{
public:


protected:


private:


};

#endif /* $h_marco */

__TEMPLATE

	open (FH, ">$h_file") or die $!;
	print FH $h_template;
	close FH;
}

my $argv_num = scalar(@ARGV);
if ($argv_num > 0)
{
	foreach my $unit (@ARGV)
	{
		gen_c($unit);
		gen_h($unit);
		print "gen $unit\.h, $unit\.cpp\n";
	}
}
else
{
	print "error!enter file name!\n";
}